import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_blobs

def plot_line(ax, slope, intercept, X):
    min_x = int(min(X[:,0]))
    max_x = int(max(X[:,0]))
    x = range(min_x,max_x)
    y = -(x*slope[0] + intercept)/slope[1]   
    ax.plot(x,y, color = 'black')
    return

CENTERS = 3  # CENTERS>2
X,y = make_blobs(n_samples=200,n_features=2,centers=CENTERS,
random_state=9, cluster_std = 0.9)
fig,axs = plt.subplots(1,3,figsize=(15,4))

for C, ax in zip([0.01, 5, 200], axs):
logistic_regression = LogisticRegression(C=C, solver = 'newton-cg', 
multi_class = 'multinomial')
    lr = logistic_regression.fit(X,y)
    for target in range(CENTERS):
        ax.scatter(X[y==target,0], X[y==target,1], label='class
                   '+format(target))
        ax.set_xlabel('Feature 1', fontsize=15); 
        ax.set_ylabel('Feature 2', fontsize=15)
        ax.set_title('Logistic Regression, C = '+str(C))
        ax.legend()
        for i in range(CENTERS):
            plot_line(ax,lr.coef_[i],lr.intercept_[i],X)     
plt.show()
